import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'default-passive-events'

import '@/styles/index.scss' // global css
import $myConfirm from './components/myConfirm'

import App from './App'
import store from './store'
import router from './router'
import directive from '@/utils/directive.js'
import * as filters from '@/utils/filters.js'
import { roundFloat } from '@/utils/math.js'
import _ from 'lodash'
import scroll from 'vue-seamless-scroll'
import './utils/rem'


Vue.use(scroll)

Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

import '@/icons' // icon
import '@/permission' // permission control
import "@/styles/animate.min.css";

Vue.use(ElementUI, { size: 'small' })
Vue.use(directive)
Vue.use($myConfirm)
// 全局组件

import  VueUeditorWrap from 'vue-ueditor-wrap'
Vue.component('vue-ueditor-wrap',VueUeditorWrap)

import ChangeGoodsInput from '@/components/ChangeGoodsInput'
Vue.component('ChangeGoodsInput', ChangeGoodsInput)

import ChangeUserInput from '@/components/ChangeUserInput'
Vue.component('ChangeUserInput', ChangeUserInput)

import TableHeaderSetting from '@/components/TableHeaderSetting'
Vue.component('TableHeaderSetting', TableHeaderSetting)

//  表格组件
import MainTable from '@/components/MainTable/table.vue'
Vue.component('MainTable', MainTable);
//  全局引入分页组件
import MainPagination from '@/components/MainPagination'
Vue.component('MainPagination', MainPagination);
//  弹窗组件
import MainDialog from '@/components/MainDialog/dialog.vue'
Vue.component('MainDialog', MainDialog);
//  表单组件
import MainSearchForm from '@/components/MainSearchForm/searchForm.vue'
Vue.component('MainSearchForm', MainSearchForm);
//  按钮组件
import MainLink from '@/components/MainLink/link.vue'
Vue.component('MainLink', MainLink);
//  详情页面头部组件
import MainGoBack from '@/components/MainGoBack/goBack.vue'
Vue.component('MainGoBack', MainGoBack);



Vue.prototype._ = _

// 表格头回调韩式添加竖线
Vue.prototype.$verticaline = function ({ row, column, rowIndex, columnIndex }) {
  if (columnIndex != 0 && columnIndex != row.length - 1) {
    return 'verticaline'
  }
}

// 全局四舍五入方法
// Vue.prototype.$toFixed = function(number, precision = 2) {
//   const func = Math.round;
//   var _sign = number < 0 ? -1 : 1;
//   precision == null
//     ? 0
//     : precision >= 0
//     ? Math.min(precision, 292)
//     : Math.max(precision, -292);
//   if (precision) {
//     let pair = `${number}e`.split("e");
//     const value =
//       func(`${pair[0] * _sign}e${+pair[1] + precision + 12}`) * _sign;
//     pair = `${value}e`.split("e");
//     let result = +`${pair[0]}e${+pair[1] - precision - 12}`;
//     result = Math.round(result * 100) / 100;
//     return result.toFixed(2);
//   }
//   return func(number);
// };
Vue.prototype.$toFixed = function (number, precision = 2) {
  return roundFloat(number, precision)
}

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App),
  beforeCreate(){
    Vue.prototype.$bus= this
   }
})
